package com.itboye.jinpuyiyuan.widget;

import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.alibaba.mobileim.IYWLoginService;
import com.alibaba.mobileim.YWAPI;
import com.alibaba.mobileim.YWIMKit;
import com.alibaba.mobileim.YWLoginParam;
import com.alibaba.mobileim.channel.event.IWxCallback;
import com.alibaba.mobileim.channel.util.YWLog;
import com.alibaba.mobileim.utility.IMNotificationUtils;
import com.itboye.jinpuyiyuan.activity.login.LoginActivity;
import com.itboye.jinpuyiyuan.app.MyApplication;
import com.itboye.jinpuyiyuan.bean.PersonBean;
import com.itboye.jinpuyiyuan.utils.IMKit.LoginSampleHelper;
import com.itboye.jinpuyiyuan.utils.IMKit.NotificationInitSampleHelper;
import com.itboye.jinpuyiyuan.utils.logincontroller.LoginController;
import com.itboye.jinpuyiyuan.utils.logincontroller.LoginedState;
import com.itboye.jinpuyiyuan.utils.logincontroller.UnLoginState;
import com.itboye.jinpuyiyuan.utils.sputil.Const;
import com.itboye.jinpuyiyuan.utils.sputil.SPUtils;
import com.itboye.jinpuyiyuan.widget.loadingutil.MAlert;

import static com.itboye.jinpuyiyuan.activity.home.finddoctor.DoctorDetailActivity.TAG;


/**
 * Created by itboye on 2017/3/15.
 * 用于发送广播调用
 */
public class FilterUtil {
    public static String LOGIN = "MeFragment";//登录
    public static String EXITLOGIN = "Exitlogin";//退出登录
    public static String HEAD = "head";
    public static YWIMKit mIMKit;


    public static void putSharePre(final Context context, final PersonBean bean) {
//        LoginController.setLoginState(new LoginedState());
//        SPUtils.put(context, null,
//                Const.PaySecret, bean.getPay_secret());
//        SPUtils.put(LoginOrRegisterActivity.this, null,
//                Const.RELE, bean.getRolesInfo().get(0).getGroupId());
//        Log.d("toten", bean.getJob_title());
        SPUtils.put(context, null,
                Const.UID, (bean.getUid()+"").toString());
        SPUtils.put(context, null,
                Const.USERNAME, bean.getUsername());

        SPUtils.put(context,null,Const.ONLINE_STATUS,bean.getOnline_status());
        SPUtils.put(context, null,
                Const.MOBILE, bean.getMobile());
        SPUtils.put(context, null,
                Const.IS_LOGINED, true);
        SPUtils.put(context, null,
                Const.HEAD, bean.getHead());
        SPUtils.put(context, null,
                Const.NICK, bean.getNickname());
//        SPUtils.put(context, null,
//                Const.EMAIL, bean.getEmail());
//        SPUtils.put(context, null,
//                Const.ISAUTH, bean.());
        SPUtils.put(context, null,
                Const.S_ID, bean.getS_id());
        SPUtils.put(context,null,Const.SEX,bean.getSex());

        if (bean.getRoles().size()!=0){
            SPUtils.put(context, null,
                    Const.ROLER, bean.getRoles().get(0));
            if (bean.getRoles().size()==2){
                SPUtils.put(context, null,
                        "roles_doctor", bean.getRoles().get(1));
            }else {
                SPUtils.put(context, null,
                        "roles_doctor", 0);
            }
        }

        SPUtils.put(context, null,
                Const.IS_ONLINE, bean.getOnline_status());
//        SPUtils.put(context,null,"role",bean.getRoles().get(0));

//        LoginSampleHelper.getInstance().initIMKit(bean.getAlibaichuan_id(),Const.OPEN_APPKEY);
        sendLoginSucceed(context);
    }

    public static void putClearSharePre(Context context) {
//        LoginController.setLoginState(new LoginedState());
//        SPUtils.put(context, null,
//                Const.PaySecret, bean.getPay_secret());
//        SPUtils.put(LoginOrRegisterActivity.this, null,
//                Const.RELE, bean.getRolesInfo().get(0).getGroupId());
//        Log.d("toten", bean.getJob_title());
        SPUtils.put(context, null,
                Const.UID, "");
        SPUtils.put(context, null,
                Const.USERNAME,"");
        SPUtils.put(context, null,
                Const.PASSWORD,"");
        SPUtils.put(context, null,
                Const.MOBILE, "");
        SPUtils.put(context, null,
                Const.IS_LOGINED, false);
        SPUtils.put(context, null,
                Const.IS_ONLINE, 1);
        SPUtils.put(context,null,
                Const.ALIBAICHUAN,"");
        if (((int)SPUtils.get(context,null,Const.ROLER,0))!=0){
            SPUtils.put(context, null,
                    Const.ROLER, 0);
            if (((int)SPUtils.get(context,null,"roles_doctor",0))!=0){
                SPUtils.put(context, null,
                        "roles_doctor", 0);
            }
        }
//        SPUtils.put(context,null,"role",0);
//        LoginSampleHelper.getInstance().initIMKit(bean.getAlibaichuan_id(),Const.OPEN_APPKEY);
       sendOutLoginSucceed(context);
    }

    //发送广播登录成功
    public static void sendLoginSucceed(Context context) {
        LoginController.setLoginState(new LoginedState());
        Intent intent = new Intent(FilterUtil.LOGIN);
        context.sendBroadcast(intent);
    }

    //发送广播退出登录
    public static void sendOutLoginSucceed(Context context) {
        LoginController.setLoginState(new UnLoginState());
        Intent intent = new Intent(FilterUtil.EXITLOGIN);
        context.sendBroadcast(intent);
    }
//
//    public static void onUserPresenter(UserPresenter presenter, String auth_code, String uid, String niceName, String Sex, String nameOPe, String xuewaStrId, String SchoolId, String Andress) {
//        if (Sex.equals("男")) {
//            Sex = "1";
//        } else {
//            Sex = "0";
//        }
//        presenter.onUpdateUser(auth_code, uid, niceName, Sex, "", nameOPe, xuewaStrId, SchoolId, "1", Andress);
//    }


}
